package com.antis.olsl.base;

import android.os.Bundle;

import androidx.viewbinding.ViewBinding;

import com.antis.olsl.base.databinding.ActivityBaseBinding;
import com.trello.rxlifecycle2.components.support.RxAppCompatActivity;

public abstract class BaseActivity<T extends ViewBinding> extends RxAppCompatActivity {
    public ActivityBaseBinding baseBinding;
    public T viewBinding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        baseBinding = ActivityBaseBinding.inflate(getLayoutInflater());
        setContentView(baseBinding.getRoot());
        viewBinding = getViewBinding();

        initPresenter();
        initViews();
        try {
            initData();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }

    protected abstract T getViewBinding();

    protected void initPresenter() {
    }

    /**
     * 子类初始化界面
     */
    protected abstract void initViews();

    /**
     * 子类初始化数据
     *
     * @throws IllegalAccessException
     */
    protected abstract void initData() throws IllegalAccessException;

    @Override
    protected void onDestroy() {
        super.onDestroy();
        baseBinding = null;
    }
}
